package com.zff.rental.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * @author HCY
 */
public class NumberInValidator implements ConstraintValidator<NumberIn, Number> {
    private long[] in;

    @Override
    public void initialize(NumberIn constraintAnnotation) {
        in = constraintAnnotation.in();
    }

    @Override
    public boolean isValid(Number value, ConstraintValidatorContext context) {
        if (in == null && value == null) {
            return true;
        }
        if (in == null || value == null) {
            return false;
        }
        for (long v : in) {
            if (v == value.longValue()) {
                return true;
            }
        }
        return false;
    }
}
